package com.xcl.controller;

import com.xcl.service.XclLogisticsServiceInter;
import com.zzg.entity.Logistics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName XclLogisticsController
 * @Description 物流承担方控制器层
 * @Author: xiaochaolei
 * @date 2021/7/9 9:48
 * @Version 1. 0
 */
@Controller
public class XclLogisticsController {
    @Autowired
    XclLogisticsServiceInter xclLogisticsServiceInter;

    /**
     * 查询物流承担方
     * @param page 页码数
     * @param limit 条目数
     * @return map集合类型的物流承担方
     */
    @GetMapping(value = "/getAllLogisticsxcl", produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> getAllLogistics(int page,int limit,String id,String forwardingunit){
        Map<String,Object> map=new HashMap<>();
        map.put("code","0");
        map.put("msg","0");
        if (id==null){
            map.put("count",xclLogisticsServiceInter.getAllLogistics().size());
            map.put("data",xclLogisticsServiceInter.getAllLogisticsByLimit(page,limit));
            return map;
        }else {
            map.put("count",xclLogisticsServiceInter.getAllLogisticsByForwardingUnit(forwardingunit,page,limit).size());
            map.put("data",xclLogisticsServiceInter.getAllLogisticsByForwardingUnit(forwardingunit,page,limit));
            return map;
        }
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @PostMapping(value = "/getLogisticsById", produces = "application/json;charset=utf-8")
    @ResponseBody
    public Logistics getLogisticsById(String id){
        return xclLogisticsServiceInter.getLogisticsById(id);
    }

    /**
     * 新增物流承担商
     * @param logistics 物流承担商信息
     * @param tms_region 地区信息
     * @return 是否成功
     */
    @PostMapping(value = "/insertLogistics", produces = "application/text;charset=utf-8")
    @ResponseBody
    public String insertLogistics(Logistics logistics, String tms_region){
        xclLogisticsServiceInter.insertLogistics(logistics,tms_region);
        return "成功";
    }

    /**
     * 修改物流承担商
     * @param logistics  物流承担商信息
     * @param tms_region 地区信息
     * @return 是否成功
     */
    @GetMapping(value = "/updateLogistics", produces = "application/text;charset=utf-8")
    @ResponseBody
    public String updateLogistics(Logistics logistics,String tms_region){
        xclLogisticsServiceInter.updateLogistics(logistics,tms_region);
        return "成功";
    }
}
